/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.insaneSolver;

import br.ufmg.dees.insane.model.femModel.FemModel;
import br.ufmg.dees.insane.parser.FemModelToPostpModel;
import br.ufmg.dees.insane.parser.XYPlotPathPostp;
import br.ufmg.dees.insane.persistence.PersistenceAsXML;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;
import br.ufmg.dees.insane.xyplot.xyplot_view.InterfaceXYPlot;

/**
 * @author Penna, S. S., Pitangueira, Roque
 * @since 14/12/2006
 */
public class ShowGraphic implements Runnable{
	private FemModelToPostpModel parser;
	private DesktopPostp parent;
	private PersistenceAsXML p;
	private SynchronizedSettings synchSettings;
	
	public ShowGraphic(DesktopPostp parent, PersistenceAsXML p){
		this.parent = parent;
		this.p = p;
	}
	
	public void run() {
		try{
			Thread.sleep(125);
			
			parser = new FemModelToPostpModel((FemModel)p.getModel());
			parser.setSolution(p.getSolution());
			(p.getModel()).addObserver(parser);
			
			
			
			XYPlotPathPostp graph = new XYPlotPathPostp((FemModel)p.getModel());
			graph.setNodeLabel(this.synchSettings.getNodeLabel());
			graph.setXValueLabel(this.synchSettings.getXAxisValue());
			graph.setYValueLabel(this.synchSettings.getYAxisValue());
			graph.setGraphTitle(this.synchSettings.getGraphicTitle());
			graph.setXAxisTitle(this.synchSettings.getXAxisTitle());
			graph.setYAxisTitle(this.synchSettings.getYAxisTitle());
			graph.setSequenceTitle(this.synchSettings.getSequenceTitle());
			graph.initXYPlot();
			
		//	p.getSolution().addObserver(graph);
			parser.addObserver(graph);
			
			InterfaceXYPlot intFrame = new InterfaceXYPlot();
			intFrame.validate();
			intFrame.setModel(graph.getXYPlotModel());
			(this.parent).addInternalFrame(intFrame);
			intFrame.toFront();
			graph.addObserver(intFrame);
			
		}catch (Exception e){
			System.out.println("ShowGraphic Class Thread Error");
		}
	}

	public SynchronizedSettings getSynchSettings() {
		return synchSettings;
	}

	public void setSynchSettings(SynchronizedSettings synchSettings) {
		this.synchSettings = synchSettings;
	}
	
//	********************************************************************************************
}// end of this class
